import axios from '@assets/request/index';
import { ref } from 'vue'
import config from '../../../project.config'
interface userInfo {
	name: string,
	HeadImg: string,
	password: string
}
interface logIn {
	name: string,
	password: string
}
//注册
export function business(data: userInfo): object {
	return axios.post('/client/business', data)
}
//登陆
export function login(data: logIn): object {
	return axios({
		url: '/client/login',
		params: data
	})
}
//获取用户数据
export function getUserData(token: string) {
	return axios({
		url: '/getdata',
		headers: {
			'x-token-shitian': token
		}
	})
}

//获取页面推荐商品
export function getList(token: string, index: number) {
	return axios.post('/homepagedata', {
		index
	},
		{
			headers: {
				'x-token-shitian': token
			}
		})
}
//获取商品详细
export function ProductDetails(businessID: string, index: string) {
	return new Promise(async (resolve) => {
		var result: any = await axios({
			url: '/roduct_details',
			params: {
				businessID,
				index
			}
		})
		var imgs = result.images.map((item: string): any => {
			return item.indexOf('http') != -1 ? item : config.ServerAddres + item
		})
		result.StoreHead=result.StoreHead.indexOf('http') != -1 ? result.StoreHead : config.ServerAddres + result.StoreHead;
		result.images = imgs;
		resolve(result)
	})
}
//加入购物车
export function AddShoppinGCart(list: any, token: string) {
	return axios.post('/appendcards', {
		list,
	},
		{
			headers: {
				'x-token-shitian': token
			}
		})
}

